package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级相关接口")
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation("查询全部护理等级")
    public ResponseResult getALlList() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.getAllList();
        return success(nursingLevelVos);
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult add(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.add(nursingLevelDto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("分页查询护理等级")
    public ResponseResult getByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageResponse pageResponse = nursingLevelService.getByPage(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult getById(@PathVariable Integer id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteById(@PathVariable Integer id) {
        nursingLevelService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("控制护理等级")
    public ResponseResult openAndClose(@PathVariable Integer id, @PathVariable Integer status) {
        nursingLevelService.openAndClose(id, status);
        return success();
    }


}
